﻿using ITSM.Model.Entity;
using ITSM.Model.Model;
using ITSM.Service;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ITSM.Controllers.DemandLink
{
    [Route("api/[controller]")]
    [ApiController]
    public class DemandLinkController : ControllerBase
    {
        private readonly IDemandTypeLink _demandTypeLink;
        public DemandLinkController(IDemandTypeLink demandTypeLink)
        {
            _demandTypeLink=demandTypeLink;
        }

        [HttpPost]
        public IActionResult AddLink(RYD_RegIt regIt) {
            if (string.IsNullOrWhiteSpace(regIt.RYD_Company)|| string.IsNullOrWhiteSpace(regIt.RYD_UserId)|| (regIt.RYD_DemandTypeNo.Length==0))
            {
                return NotFound();
            }
            return Ok(_demandTypeLink.AddDemandTypeLink(regIt.RYD_UserId, regIt.RYD_Company, regIt.RYD_DemandTypeNo));
        }
        [HttpPut]
        public IActionResult PutLink(RYD_RegIt typeLink) {
            if (string.IsNullOrWhiteSpace(typeLink.RYD_Company)|| string.IsNullOrWhiteSpace(typeLink.RYD_UserId)|| (typeLink.RYD_DemandTypeNo.Length==0))
            {
                return NotFound();
            }
            return Ok(_demandTypeLink.DeleteDemandTypeLink(typeLink));
        }
    }
}
